﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Main.Master" AutoEventWireup="true"
    CodeBehind="PaymentMachineAccountInfoManagement.aspx.cs" Inherits="NetDon.OA.Portal.Finance.PaymentMachineAccountInfoManagement" %>

<%@ Import Namespace="NetDon.OA.Interface" %>
<%@ Import Namespace="NetDon.OA.Portal" %>
<%@ Import Namespace="NetDon.Utilities" %>
<%@ Register Src="../Controls/GridPager.ascx" TagName="GridPager" TagPrefix="uc1" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <script language="javascript" type="text/javascript">
        var userDialogSize = { width: 900, height: window.top.$common.getClientBounds().height - 200 };
        function createIssuingOrderInfo(issuingOrderId) {
            $dialog('<%=ResolveUrl("~/Finance/PaymentMachineAccountInfoEdit.aspx") %>?IssuingOrderId=' + issuingOrderId, { width: 1000, height: window.top.$common.getClientBounds().height - 200 }, function (result) {
                if (result) {
                    $get('<%=btnReload.ClientID %>').click();
                }
            });
        }

        function searchDailyFinancialDetails() {
            $dialog('<%=ResolveUrl("~/Finance/DailyFinancialDetailsQuery.aspx") %>', userDialogSize, function (result) {
                if (result) {

                }
            });
        }


        function deleteOrder(orderId, paymentOrIncome) {
            $confirm("确定要删除该笔付款或收入明细吗？", function (result) {
                if (result) {
                    $text($get('<%=fieldOrderId.ClientID %>'), orderId);
                    $text($get('<%=fieldpaymentOrIncome.ClientID %>'), paymentOrIncome);
                    $get('<%=btnHiddenDelete.ClientID %>').click();
                }
            });
        }

        function confirmOrderClosure(orderId, paymentOrIncome) {
            $confirm("确定此订单已结案吗？", function (result) {
                if (result) {
                    $text($get('<%=fieldOrderId.ClientID %>'), orderId);
                    $get('<%=btnHiddenConfirmOrderClosure.ClientID %>').click();
                }
            });
        }

        function viewOrderPayment(sender, args) {
            var orderId = $attr(sender.get_selectedRow(), 'Id');
            var paymentOrIncome = $attr(sender.get_selectedRow(), 'PaymentOrIncome');
            $dialog('<%= ResolveUrl("~/Finance/PaymentMachineAccountInfoEdit.aspx")%>?Id=' + orderId + '&paymentOrIncome=' + paymentOrIncome, userDialogSize, function (result) {
                if (result) {
                    $get('<%=btnReload.ClientID %>').click();
                }
            });
        }


        function modifyOrderPayment(orderId, paymentOrIncome, issuingOrderId,isViewModel) {
            $dialog('<%=ResolveUrl("~/Finance/PaymentMachineAccountInfoEdit.aspx") %>?Id=' + orderId + '&paymentOrIncome=' + paymentOrIncome + '&IssuingOrderId=' + issuingOrderId + '&isViewModel=' + isViewModel, userDialogSize, function (result) {
                if (result) {
                    $get('<%=btnReload.ClientID %>').click();
                }
            });
        }
        
        function SelectAll(evtObj) {
            Array.forEach($array($get('<%=gridOrderList.ClientID %>').getElementsByTagName("input")), function (elt) {

                if (elt.type == "checkbox" && elt.disabled == false) {
                    elt.checked = evtObj.checked;
                }
            });
        }
        function SendSelected(evtObj) {
            var count = 0;
            Array.forEach($array($get('<%=gridOrderList.ClientID %>').getElementsByTagName("input")), function (elt) {
                if (elt.type == "checkbox" && elt.id != 'checkAll' && elt.checked) {
                    count++;
                }
            });
            if (count == 0) {
                $alert("请至少选择一笔记录。");
                return false;
            }
            return true;
        }
  
    </script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <asp:UpdatePanel ID="UpdatePanelFlow" runat="server">
        <ContentTemplate>
            <asp:Panel ID="Panel1" runat="server" DefaultButton="btnSearch">
                <table border="0" cellpadding="0" cellspacing="0">
                    <tr>
                        <td>
                            <NetDon:FormPanel ID="PanelCondition" runat="server" CaptionAlign="NotSet" RepeatColumns="3">
                                <Items>
                                    <NetDon:FormItem HeaderText="订单编号">
                                        <ContentTemplate>
                                            <asp:TextBox ID="txtOrderCode" runat="server"></asp:TextBox>
                                        </ContentTemplate>
                                    </NetDon:FormItem>
                                    <NetDon:FormItem HeaderText="运输计划号">
                                        <ContentTemplate>
                                            <asp:TextBox ID="txtTransportationPlanCode" runat="server"></asp:TextBox>
                                        </ContentTemplate>
                                    </NetDon:FormItem>
                                                    <NetDon:FormItem HeaderText="线路分类">
                                        <ContentTemplate>
                                            <asp:DropDownList ID="ddlRouteTypeId" DataSourceID="ddsRouteTypeId" AppendDataBoundItems="True"
                                                runat="server" DataTextField="Name" DataValueField="Value">
                                            </asp:DropDownList>
                                            <NetDon:DictionaryDataSource ID="ddsRouteTypeId" runat="server" CategoryName="线路分类"
                                                EmptyItemType="Select">
                                            </NetDon:DictionaryDataSource>
                                        </ContentTemplate>
                                    </NetDon:FormItem>
                                      <NetDon:FormItem HeaderText="出单日期">
                                        <ContentTemplate>
                                            <asp:TextBox ID="txtReceivingOrderDateStart" runat="server" Width="75px"></asp:TextBox>
                                            <asp:CalendarExtender ID="txtReceivingOrderDateStart_CalendarExtender" runat="server"
                                                Enabled="True" TargetControlID="txtReceivingOrderDateStart" Format="yyyy-MM-dd">
                                            </asp:CalendarExtender>
                                            <asp:Label ID="Label2" runat="server" Text="~" Style="margin-left: 5px; margin-right: 6px"></asp:Label>
                                            <asp:TextBox ID="txtReceivingOrderDateEnd" runat="server" Width="75px"></asp:TextBox>
                                            <asp:CalendarExtender ID="txtReceivingOrderDateEnd_CalendarExtender" runat="server"
                                                Enabled="True" TargetControlID="txtReceivingOrderDateEnd" Format="yyyy-MM-dd">
                                            </asp:CalendarExtender>
                                        </ContentTemplate>
                                    </NetDon:FormItem>
                                    <NetDon:FormItem HeaderText="付款或收入日期">
                                        <ContentTemplate>
                                            <asp:TextBox ID="txtPaymentOrIncomeDateStart" runat="server" Width="75px"></asp:TextBox>
                                            <asp:CalendarExtender ID="CalendarExtender1" runat="server" Enabled="True" TargetControlID="txtPaymentOrIncomeDateStart"
                                                Format="yyyy-MM-dd">
                                            </asp:CalendarExtender>
                                            <asp:Label ID="Label1" runat="server" Text="~" Style="margin-left: 5px; margin-right: 6px"></asp:Label>
                                            <asp:TextBox ID="txtPaymentOrIncomeDateEnd" runat="server" Width="75px"></asp:TextBox>
                                            <asp:CalendarExtender ID="CalendarExtender2" runat="server" Enabled="True" TargetControlID="txtPaymentOrIncomeDateEnd"
                                                Format="yyyy-MM-dd">
                                            </asp:CalendarExtender>
                                        </ContentTemplate>
                                    </NetDon:FormItem>
                    
                                    <NetDon:FormItem HeaderText="付款方式">
                                        <ContentTemplate>
                                            <asp:DropDownList ID="ddlPaymentMethod" DataSourceID="ddsPaymentMethod" AppendDataBoundItems="True"
                                                runat="server" DataTextField="Name" DataValueField="Value">
                                            </asp:DropDownList>
                                            <NetDon:DictionaryDataSource ID="ddsPaymentMethod" runat="server" CategoryName="付款方式"
                                                EmptyItemType="Select">
                                            </NetDon:DictionaryDataSource>
                                        </ContentTemplate>
                                    </NetDon:FormItem>
                                    <NetDon:FormItem HeaderText="收入或支出">
                                        <ContentTemplate>
                                            <asp:RadioButton ID="ckbIsMachineAccountAll" Checked="True" runat="server" Text="全部"
                                                GroupName="MachineAccount"></asp:RadioButton>
                                            <asp:RadioButton ID="ckbIsMachineAccountIncome" runat="server" Text="收入" GroupName="MachineAccount">
                                            </asp:RadioButton>
                                            <asp:RadioButton ID="ckbIsMachineAccountPayment" runat="server" Text="支出" GroupName="MachineAccount">
                                            </asp:RadioButton>
                                        </ContentTemplate>
                                    </NetDon:FormItem>
                                    <NetDon:FormItem HeaderText="承运公司">
                                        <ContentTemplate>
                                            <asp:DropDownList ID="ddlCompany" runat="server" DataSourceID="ObjectDataSourceCompany"
                                                DataTextField="CompanyName" DataValueField="CompanyId" AppendDataBoundItems="true">
                                            </asp:DropDownList>
                                            <asp:ObjectDataSource ID="ObjectDataSourceCompany" runat="server" OldValuesParameterFormatString="original_{0}"
                                                SelectMethod="RetrieveCompanies" TypeName="NetDon.OA.Business.MiscDataSource">
                                            </asp:ObjectDataSource>
                                        </ContentTemplate>
                                    </NetDon:FormItem>
                                </Items>
                            </NetDon:FormPanel>
                        </td>
                        <td valign="bottom">
                            <asp:Button ID="btnSearch" SkinID="Button60" runat="server" OnClick="btnSearch_Click"
                                Text="查询"></asp:Button>
                            <asp:Button ID="btnReload" runat="server" SkinID="Hidden" OnClick="btnReload_Click" />
                            <asp:Button ID="btnSearchDailyFinancialDetails" SkinID="Button120" runat="server"
                                OnClick="btnSearchDailyFinancialDetails_Click" Text="查询每日财务明细"></asp:Button>
                            <asp:Button ID="btnAutoConfirmOrderClosure" SkinID="Button120" runat="server" OnClick="btnAutoConfirmOrderClosure_Click"
                                Text="订单自动结案" Visible="False"></asp:Button>
                        </td>
                    </tr>
                </table>
            </asp:Panel>
            <div style="margin-top: 10px">
                <NetDon:GridView ID="gridOrderList" runat="server" AutoGenerateColumns="False" AllowSorting="true"
                    DataKeyNames="Id" OnRowDataBound="gridOrderList_RowDataBound" OnRowDetailCreated="gridProductList_RowDetailCreated">
                    <Columns>
                        <%--                       <NetDon:TemplateField>
                            <HeaderStyle HorizontalAlign="Center" />
                            <HeaderTemplate>
                                <asp:CheckBox ID="chkSelectAll" runat="server" onclick="SelectAll(this)" />
                            </HeaderTemplate>
                            <ItemStyle HorizontalAlign="Center" />
                            <ItemTemplate>
                                <asp:CheckBox ID="chkSelect" runat="server" />
                            </ItemTemplate>
                        </NetDon:TemplateField>--%>
                        <NetDon:BoundField HeaderText="订单编号" DataField="OrderCode" SortExpression="OrderCode">
                        </NetDon:BoundField>
                        <NetDon:BoundField HeaderText="出单日期" DataField="ReceivingOrderDate" DataFormatString="{0:yyyy-MM-dd}"
                            SortExpression="ReceivingOrderDate">
                        </NetDon:BoundField>
                        <NetDon:BoundField HeaderText="实发货日期" DataField="ActualShippingDate" DataFormatString="{0:yyyy-MM-dd}"
                            SortExpression="ActualShippingDate">
                        </NetDon:BoundField>
                        <%--                 <NetDon:TemplateField HeaderText="业务类型" SortExpression="BusinessType">
                            <ItemTemplate>
                                <%#EnumUtilities.GetDescription((BusinessType)Enum.Parse(typeof(BusinessType), Eval("BusinessType").ToString()))%>
                            </ItemTemplate>
                        </NetDon:TemplateField>--%>
                        <NetDon:BoundField HeaderText="运输计划号" DataField="TransportationPlanCode" SortExpression="TransportationPlanCode">
                        </NetDon:BoundField>
                        <NetDon:TemplateField HeaderText="线路分类" SortExpression="RouteTypeId">
                            <ItemTemplate>
                                <%#GetDictionaryItemName(Eval("RouteTypeId"))%>
                            </ItemTemplate>
                        </NetDon:TemplateField>
                        <asp:TemplateField HeaderText="总收入(￥)" SortExpression="IncomeAmount">
                            <ItemTemplate>
                                <%#! MiscUtilities.IsNullOrEmpty(Eval("IncomeAmount")) ? ((Decimal)Eval("IncomeAmount")).ToString("#,###.00") : ""%>
                            </ItemTemplate>
                            <ItemStyle HorizontalAlign="Right"></ItemStyle>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="应付运费（成本）(￥)" SortExpression="DueShippingCost">
                            <ItemTemplate>
                                <%#! MiscUtilities.IsNullOrEmpty(Eval("DueShippingCost")) ? ((Decimal)Eval("DueShippingCost")).ToString("#,###.00") : ""%>
                            </ItemTemplate>
                            <ItemStyle HorizontalAlign="Right"></ItemStyle>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="已付运费(￥)" SortExpression="TobePaidShippingCost">
                            <ItemTemplate>
                                <%#!MiscUtilities.IsNullOrEmpty(Eval("TobePaidShippingCost")) ? ((Decimal)Eval("TobePaidShippingCost")).ToString("#,###.00") : ""%>
                            </ItemTemplate>
                            <ItemStyle HorizontalAlign="Right"></ItemStyle>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="待付运费(￥)" SortExpression="PendingShippingCost">
                            <ItemTemplate>
                                <%#! MiscUtilities.IsNullOrEmpty(Eval("PendingShippingCost")) ? ((Decimal)Eval("PendingShippingCost")).ToString("#,###.00") : ""%>
                            </ItemTemplate>
                            <ItemStyle HorizontalAlign="Right"></ItemStyle>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="扣罚司机金额(￥)" SortExpression="DeductionExceptionsAmount">
                            <ItemTemplate>
                                <%#! MiscUtilities.IsNullOrEmpty(Eval("DeductionExceptionsAmount")) ? ((Decimal)Eval("DeductionExceptionsAmount")).ToString("#,###.00") : ""%>
                            </ItemTemplate>
                            <ItemStyle HorizontalAlign="Right"></ItemStyle>
                        </asp:TemplateField>
                        <NetDon:TemplateField HeaderText="订单状态" SortExpression="OrderStatus">
                            <ItemTemplate>
                                <%#EnumUtilities.GetDescription((OrderStatus)Enum.Parse(typeof(OrderStatus),Eval("OrderStatus").ToString()))%>
                            </ItemTemplate>
                        </NetDon:TemplateField>
                        <NetDon:TemplateField HeaderText="操作" ItemStyle-Width="80px">
                            <ItemTemplate>
                                <asp:ImageButton ID="btnCreateNew" runat="server" SkinID="Add" ImageAlign="AbsMiddle"
                                    CausesValidation="false" />
                              <%--  <asp:ImageButton ID="btnConfirmOrderClosure" runat="server" SkinID="ConfirmOrder"
                                    ImageAlign="AbsMiddle" CausesValidation="false" Visible="False" />--%>
                            </ItemTemplate>
                        </NetDon:TemplateField>
                    </Columns>
                    <DetailSettings HeaderText="订单付款或收入" ColumnWidth="100px" CollapseText="隐藏" ExpandText="查看"
                        ExpandImageUrl="~/Images/Button/expand.jpg" CollapseImageUrl="~/Images/Button/collapse.jpg"
                        TargetControlID="pnlOrderPayment">
                    </DetailSettings>
                </NetDon:GridView>
                <uc1:GridPager ID="PageQueryAdapter1" runat="server" TargetControlID="gridOrderList"
                    OnPerformGetCondition="PageQueryAdapter1_PerformGetCondition" OnPerformGetRecordCount="PageQueryAdapter1_PerformGetRecordCount"
                    OnPerformGetPageData="PageQueryAdapter1_PerformGetPageData" />
            </div>
            <asp:Panel ID="pnlOrderPayment" runat="server" Visible="false" ScrollBars="None"
                BorderColor="White">
                <div style="width: 900px; overflow-x: auto;">
                    <asp:GridView ID="grdOrderPayment" BorderWidth="0px" CellPadding="0" CellSpacing="0"
                        Width="100%" AutoGenerateColumns="false" runat="server" OnClientRowDblClick="viewOrderPayment"
                        OnRowDataBound="grdOrderPayment_RowDataBound">
                        <Columns>
                            <asp:BoundField HeaderText="付款或收入日期" DataField="PaymentOrIncomeDate" DataFormatString="{0:yyyy-MM-dd}"
                                SortExpression="PaymentOrIncomeDate"></asp:BoundField>
                            <asp:TemplateField HeaderText="收入或支出">
                                <ItemTemplate>
                                    <%#EnumUtilities.GetDescription((MachineAccountType)Enum.Parse(typeof(MachineAccountType), Eval("PaymentOrIncome").ToString()))%>
                                </ItemTemplate>
                            </asp:TemplateField>
                            <asp:TemplateField HeaderText="收入方式">
                                <ItemTemplate>
                                    <%#GetDictionaryItemName(Eval("IncomeType"))%>
                                </ItemTemplate>
                            </asp:TemplateField>
                            <asp:TemplateField HeaderText="收入(￥)">
                                <ItemTemplate>
                                    <%#! MiscUtilities.IsNullOrEmpty(Eval("IncomeAmount")) ? ((Decimal)Eval("IncomeAmount")).ToString("#,###.00") : ""%>
                                </ItemTemplate>
                                <ItemStyle HorizontalAlign="Right"></ItemStyle>
                            </asp:TemplateField>
                            <asp:TemplateField HeaderText="其它收入(￥)">
                                <ItemTemplate>
                                    <%#! MiscUtilities.IsNullOrEmpty(Eval("OtherIncome")) ? ((Decimal)Eval("OtherIncome")).ToString("#,###.00") : ""%>
                                </ItemTemplate>
                                <ItemStyle HorizontalAlign="Right"></ItemStyle>
                            </asp:TemplateField>
                            <%--<asp:TemplateField HeaderText="应付运费（成本）(￥)">
                                <ItemTemplate>
                                    <%#! MiscUtilities.IsNullOrEmpty(Eval("DueShippingCost")) ? ((Decimal)Eval("DueShippingCost")).ToString("#,###.00") : ""%>
                                </ItemTemplate>
                                <ItemStyle HorizontalAlign="Right"></ItemStyle>
                            </asp:TemplateField>
                            <asp:TemplateField HeaderText="已付运费(￥)">
                                <ItemTemplate>
                                    <%#! MiscUtilities.IsNullOrEmpty(Eval("PaidShippingCost")) ? ((Decimal)Eval("PaidShippingCost")).ToString("#,###.00") : ""%>
                                </ItemTemplate>
                                <ItemStyle HorizontalAlign="Right"></ItemStyle>
                            </asp:TemplateField>
                            <asp:TemplateField HeaderText="待付运费(￥)">
                                <ItemTemplate>
                                    <%#! MiscUtilities.IsNullOrEmpty(Eval("PendingShippingCost")) ? ((Decimal)Eval("PendingShippingCost")).ToString("#,###.00") : ""%>
                                </ItemTemplate>
                                <ItemStyle HorizontalAlign="Right"></ItemStyle>
                            </asp:TemplateField>--%>
                            <asp:TemplateField HeaderText="支出金额(￥)">
                                <ItemTemplate>
                                    <%#!MiscUtilities.IsNullOrEmpty(Eval("TobePaidShippingCost")) ? ((Decimal)Eval("TobePaidShippingCost")).ToString("#,###.00") : ""%>
                                </ItemTemplate>
                                <ItemStyle HorizontalAlign="Right"></ItemStyle>
                            </asp:TemplateField>
                            <asp:TemplateField HeaderText="装卸费(￥)">
                                <ItemTemplate>
                                    <%#!MiscUtilities.IsNullOrEmpty(Eval("GoodsUnloadingCost")) ? ((Decimal)Eval("GoodsUnloadingCost")).ToString("#,###.00") : ""%>
                                </ItemTemplate>
                                <ItemStyle HorizontalAlign="Right"></ItemStyle>
                            </asp:TemplateField>
                            <asp:TemplateField HeaderText="工厂扣罚(￥)">
                                <ItemTemplate>
                                    <%#!MiscUtilities.IsNullOrEmpty(Eval("OtherAmountFromManufactor")) ? ((Decimal)Eval("OtherAmountFromManufactor")).ToString("#,###.00") : ""%>
                                </ItemTemplate>
                                <ItemStyle HorizontalAlign="Right"></ItemStyle>
                            </asp:TemplateField>
                            <asp:TemplateField HeaderText="付款方式" SortExpression="PaymentMethod">
                                <ItemTemplate>
                                    <%#!MiscUtilities.IsNullOrEmpty(Eval("PaymentMethod")) ? GetDictionaryItemName(Eval("PaymentMethod")) : string.Empty%>
                                </ItemTemplate>
                            </asp:TemplateField>
                            <asp:TemplateField HeaderText="扣款金额(￥)">
                                <ItemTemplate>
                                    <%#! MiscUtilities.IsNullOrEmpty(Eval("DeductionExceptionsAmount")) ? ((Decimal)Eval("DeductionExceptionsAmount")).ToString("#,###.00") : ""%>
                                </ItemTemplate>
                                <ItemStyle HorizontalAlign="Right"></ItemStyle>
                            </asp:TemplateField>
                            <asp:BoundField HeaderText="更新时间" DataField="LastUpdatedDate" SortExpression="LastUpdatedDate"
                                DataFormatString="{0:yyyy-MM-dd}"></asp:BoundField>
                            <asp:BoundField HeaderText="更新人" SortExpression="LastUpdatedBy" DataField="UserName">
                            </asp:BoundField>
                            <asp:TemplateField HeaderText="操作" ItemStyle-Width="100px">
                                <ItemTemplate>
                                    <asp:ImageButton ID="btnDetails" Style="margin-left: 5px" ToolTip="Details" runat="server"
                                        SkinID="ViewDetail" ImageAlign="AbsMiddle" CausesValidation="false" />
                                           <asp:ImageButton ID="btnEdit" runat="server" SkinID="Modify" ImageAlign="AbsMiddle"
                                    CausesValidation="false" />
                                    <asp:ImageButton ID="btnDelete" runat="server" SkinID="Delete" />
                                </ItemTemplate>
                            </asp:TemplateField>
                        </Columns>
                        <HeaderStyle CssClass="test" />
                        <RowStyle CssClass="test" />
                        <AlternatingRowStyle CssClass="GridRow1" />
                    </asp:GridView>
                </div>
            </asp:Panel>
            <asp:HiddenField ID="fieldOrderId" runat="server" />
            <asp:HiddenField ID="fieldpaymentOrIncome" runat="server" />
            <asp:Button ID="btnHiddenDelete" runat="server" OnClick="btnDelete_Click" Text="Delete"
                SkinID="Hidden" />
            <asp:Button ID="btnHiddenConfirmOrderClosure" runat="server" OnClick="btnHiddenConfirmOrderClosure_Click"
                Text="Delete" SkinID="Hidden" />
        </ContentTemplate>
    </asp:UpdatePanel>
    <script type="text/javascript">


        function pageLoad() {
            setTimeout(function () {
                function showDetail(index) {
                    var grid = $find('<%=gridOrderList.ClientID%>');
                    if (grid._rows.length <= index) return;
                    var row = grid._rows[index];
                    var elements = row.getElementsByTagName("input"); //the last input is the details loading 
                    grid.showDetail(index, elements[elements.length - 1], function () {
                        showDetail(index + 1);
                    });
                }

                showDetail(0);

            }, 0);
        }

    </script>
</asp:Content>
